package com.yunji.cabinet.service.impl;

import com.yunji.cabinet.context.convert.UpgradeTaskConvert;
import com.yunji.cabinet.bo.UpgradeTaskListBO;
import com.yunji.cabinet.dao.IUpgradeTaskDao;
import com.yunji.cabinet.domain.UpgradeTaskDO;
import com.yunji.cabinet.params.UpgradeTaskParam;
import com.yunji.cabinet.service.IUpgradeTaskService;
import com.yunji.cabinet.vo.UpgradeTaskVO;
import com.yunji.common.base.IModifyStatusBaseBO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class UpgradeTaskServiceImpl implements IUpgradeTaskService {

    @Resource
    private IUpgradeTaskDao upgradeTaskDao;

    @Override
    public boolean create(UpgradeTaskDO upgradeTaskDO) {
        return upgradeTaskDao.save(upgradeTaskDO);
    }

    @Override
    public boolean modifyStatus(String taskCode, Integer newStatus, ArrayList<Integer> oldStatus) {
        return upgradeTaskDao.modifyStatus(new IModifyStatusBaseBO<String>() {
            @Override
            public String getId() {
                return taskCode;
            }

            @Override
            public Integer getNewStatus() {return newStatus;}
            @Override
            public List<Integer> getOldStatus() {return oldStatus;}
        });
    }

    @Override
    public boolean startTask(String taskCode) {
        return upgradeTaskDao.startTask(taskCode);
    }

    @Override
    public boolean closeTask(String taskCode) {
        return upgradeTaskDao.closeTask(taskCode);
    }

    @Override
    public List<UpgradeTaskVO> searchVOList(UpgradeTaskParam param) {
        List<UpgradeTaskDO> list = upgradeTaskDao.searchPageList(param);
        return UpgradeTaskConvert.domainTOVOList(list);
    }

    @Override
    public UpgradeTaskVO selectVO(String taskCode) {
        return UpgradeTaskConvert.domainTOVO(upgradeTaskDao.getById(taskCode));
    }

    @Override
    public List<UpgradeTaskDO> search(UpgradeTaskListBO bo) {


        return upgradeTaskDao.search(bo);
    }
}
